package org.example.util;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;

/**
 * @author wxy
 * @since 2025/4/3
 **/
public class PageUtils {

    public static <T> IPage<T> listToPage(List<T> approvalList, Integer pageNum, Integer pageSize) {
        int listSize = approvalList.size();
        int startIndex = Math.min((pageNum - 1) * pageSize, listSize);
        int endIndex = Math.min(startIndex + pageSize, listSize);
        List<T> records = approvalList.subList(startIndex, endIndex);
        Page<T> page = new Page<>(pageNum, pageSize);
        page.setRecords(records).setTotal(listSize);
        return page;
    }
}